﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.Web.Security;

namespace JCSoft.Collect.Web.Controller
{
    public class UserController : BaseController
    {
        public ActionResult Login()
        {
            return View();
        }

        [AcceptVerbs("Post")]
        public ActionResult Login(string username, string password)
        {
            var user = this.MiddleTier.UserManager.GetUser(username, password);

            if (user != null)
            {
                WebUtility.SetAuthCookie(this.HttpContext, user);    
                return RedirectToAction("Login");
            }

            return View();
        }

        public ActionResult LogOff()
        {
            this.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMinutes(-1);
            return RedirectToAction("Login");
        }
    }
}
